package com.bytz.modules.cms.echop.model;

import com.bytz.modules.cms.domain.util.DecimalFormatUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Getter
@Setter
public class ContractDocBo {

    @JsonProperty("客户公司名称")
    @ApiModelProperty(value = "需方单位名称")
    private String demanderName;

    @JsonProperty("合同号码")
    @ApiModelProperty(value = "合同号")
    private String contractNumber;

    @JsonProperty("拟定日期")
    @ApiModelProperty(value = "完成时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDateTime completeTime;

    @JsonProperty("客户编号")
    @ApiModelProperty(value = "需方客户编码")
    private String demanderNumber;

    @JsonProperty("表格1")
    @ApiModelProperty("订单项目")
    private List<ContractItemDocBo> items;

    public String getItems() throws JsonProcessingException {
        return new ObjectMapper().writeValueAsString(items);
    }

    @JsonProperty("合计含税总价")
    @ApiModelProperty(value = "订单总额")
    private BigDecimal totalPrice;

    public String getTotalPrice() {
        return DecimalFormatUtil.formatMoney(totalPrice);
    }

    @JsonProperty("交付地点")
    @ApiModelProperty(value = "需方交付单位地址")
    private String shipToAddress;

    @JsonProperty("收货联系人")
    @ApiModelProperty(value = "需方交付联系人")
    private String shipToContact;

    @JsonProperty("手机号")
    @ApiModelProperty(value = "需方交付联系人电话")
    private String shipToPhone;

    @JsonProperty("第几周")
    @ApiModelProperty("订单标准交期(日)")
    private Integer deliveryDate;

    /**
     * 获取订单标准交期(周)
     */
    public String getDeliveryDate() {
        return String.valueOf(deliveryDate / 7);
    }

    @JsonProperty("付款比例")
    @ApiModelProperty(value = "预付比例")
    private BigDecimal prepayRatio;

    public String getPrepayRatio() {
        return DecimalFormatUtil.formatPercentWithoutSymbol(prepayRatio);
    }

    @JsonProperty("余额")
    private String balance = "余款";

    @JsonProperty("发票寄送地址")
    @ApiModelProperty(value = "需方单位地址")
    private String demanderAddress;

    @JsonProperty("发票地址联系人")
    @ApiModelProperty(value = "需方联系人")
    private String demanderContact;

    @JsonProperty("发票联系人手机号")
    @ApiModelProperty(value = "需方电话")
    private String demanderPhone;

    @JsonProperty("发货地址")
    public String getShipToAddressForJson() {
        return shipToAddress;
    }

    @JsonProperty("发货联系人")
    public String getShipToContactForJson() {
        return shipToContact;
    }

    @JsonProperty("发货联系人手机号")
    public String getShipToPhoneForJson() {
        return shipToPhone;
    }

    @JsonProperty("质保月数")
    @ApiModelProperty(value = "质保期")
    private String warrantyPeriod;

    @JsonProperty("违约金百分比")
    private String percentageOfPenalty = "0.05%";

    @JsonProperty("需方地址")
    public String getDemanderAddressForJson() {
        return demanderAddress;
    }

    @JsonProperty("需方邮编")
    @ApiModelProperty(value = "需方邮政编码")
    private String demanderPostcode;

    @JsonProperty("需方代理人")
    @ApiModelProperty(value = "需方委托代理人")
    private String demanderAgent;

    @JsonProperty("供方代理人")
    @ApiModelProperty(value = "销售人员名字 (供方委托代理人)")
    private String salesName;

    @JsonProperty("需方电话")
    @ApiModelProperty(value = "需方电话")
    public String getDemanderPhoneForJson() {
        return demanderPhone;
    }

    @JsonProperty("需方传真")
    @ApiModelProperty(value = "需方传真")
    private String demanderFax;

    @JsonProperty("需方日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "需方签约日期：订单提交日期")
    private LocalDateTime demanderSignedDate;

    @JsonProperty("供方电话")
    @ApiModelProperty(value = "供方电话")
    private String supplierPhone;

    @JsonProperty("供方传真")
    @ApiModelProperty(value = "供方传真")
    private String supplierFax;

    @JsonProperty("供方日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    public LocalDateTime getCompleteTimeForJson() {
        return completeTime;
    }
}
